package com.example.common.util;

import lombok.experimental.UtilityClass;

import java.io.File;
import java.util.Objects;
import java.util.stream.Stream;

/**
 * @Description fileUtil
 * @date 2020-04-09 16:35
 **/
@UtilityClass
public class FileUtils {

    public static void renameFiles(String dir, String from, String to){
        File file = new File(dir);
        Stream.of(Objects.requireNonNull(file.listFiles()))
                .filter(t-> t.getName().contains(from))
                .forEach(t-> t.renameTo(new File(dir+File.separator+t.getName().replace(from,to))));
    }

//    public static void main(String[] args) {
//        String dir = "C:\\Users\\pywang\\Desktop\\仪器系统\\working";
//        renameFiles(dir, "2019", "2021");
//        File file = new File(dir);
//        Stream.of(Objects.requireNonNull(file.listFiles()))
//                .forEach(t-> System.out.println(t.getName()));
//    }
}
